home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok20.lha
/
ComplexLib
/
txt
/
LongMathLibExt.mod
< prev
next >
Wrap
Text File
|
1993-08-15
|
4KB
|
184 lines
(*********************************************************************
:Program. LongMathLibExt.mod
:Author. Gary Struhlik
:Address. -
:Phone. -
:shortcut. [gs]
:Version. 1.0
:Date. 06.10.1988
:Copyright. PD
:Language. Modula-II
:Translator. M2Amiga
:Imports. -
:UpDate. -
:Contents. Zusätzliche mathematische Funktionen
:Remark. Für den Amiga Modula-2 Klub / Stuttgart
:Remark. Am 01.01.1989 mit M2Amiga 3.2d neu kompiliert
**********************************************************************)
IMPLEMENTATION MODULE LongMathLibExt; (* für Datentyp LONGREAL *)
FROM MathLibLong IMPORT sin,cos,ln,exp,sqrt,arctan;
PROCEDURE round ( x : LONGREAL ) : LONGINT;
BEGIN
IF x >= 0.0 THEN RETURN TRUNC( x + 0.5 )
ELSE RETURN TRUNC( x - 0.5 )
END (* IF *)
END round;
PROCEDURE sqr ( x : LONGREAL ) : LONGREAL;
BEGIN
RETURN x*x
END sqr;
PROCEDURE tan ( x : LONGREAL ) : LONGREAL;
BEGIN
RETURN sin(x)/cos(x)
END tan;
PROCEDURE arcsin ( x : LONGREAL ) : LONGREAL;
BEGIN
IF x=1.0 THEN RETURN pi/2.0
ELSIF x=-1.0 THEN RETURN -pi/2.0
ELSE
RETURN arctan(x/sqrt(1.0-x*x))
END
END arcsin;
PROCEDURE arccos ( x : LONGREAL ) : LONGREAL;
BEGIN
IF x=1.0 THEN RETURN 0.0
ELSIF x=-1.0 THEN RETURN pi
ELSE
RETURN pi/2.0-arcsin(x)
END
END arccos;
PROCEDURE sinh ( x : LONGREAL ) : LONGREAL;
BEGIN
RETURN 0.5*(exp(x)-exp(-x))
END sinh;
PROCEDURE cosh ( x : LONGREAL ) : LONGREAL;
BEGIN
RETURN 0.5*(exp(x)+exp(-x))
END cosh;
PROCEDURE tanh ( x : LONGREAL ) : LONGREAL;
BEGIN
RETURN sinh(x)/cosh(x)
END tanh;
PROCEDURE log ( x : LONGREAL ) : LONGREAL;
BEGIN
RETURN ln(x)/ln10
END log;
PROCEDURE PwrOfTen ( x : LONGREAL ) : LONGREAL;
BEGIN
RETURN exp(x*ln10)
END PwrOfTen;
PROCEDURE lb ( x : LONGREAL ) : LONGREAL;
BEGIN
RETURN ln(x)/ln2
END lb;
PROCEDURE PwrOfTwo ( x : LONGREAL ) : LONGREAL;
BEGIN
RETURN exp(x*ln2)
END PwrOfTwo;
PROCEDURE arsinh ( x : LONGREAL ) : LONGREAL;
BEGIN
RETURN ln( x + sqrt( x*x + 1.0))
END arsinh;
PROCEDURE arcosh ( x : LONGREAL ) : LONGREAL;
BEGIN
IF (x > 1.0) THEN RETURN ln( x + sqrt( x*x - 1.0)) (* für x # 1.0 *)
ELSIF x=1.0 THEN RETURN 0.0
END (* IF *)
END arcosh;
PROCEDURE artanh ( x : LONGREAL ) : LONGREAL;
BEGIN
RETURN 0.5*ln( (1.0+x)/(1.0-x) ) (* für x # 1.0 *)
END artanh;
PROCEDURE power ( x,y : LONGREAL ) : LONGREAL; (* x^y *)
VAR
wert,n : LONGREAL;
i : INTEGER;
BEGIN
IF (x = 0.0) AND (y = 0.0) THEN
RETURN 1.0E-308
ELSIF x = 0.0 THEN
RETURN 0.0
ELSIF y = 0.0 THEN
RETURN 1.0
ELSIF x > 0.0 THEN
IF ( y-LONGREAL(TRUNC(y)) <> 0.0 ) THEN
RETURN exp(y*ln(x))
ELSE
n:=1.0;
FOR i:=1 TO ABS(TRUNC(y)) DO
n:=n*x
END; (* FOR *)
IF y > 0.0 THEN
RETURN n
ELSE
RETURN 1.0/n
END (* IF y > 0.0 *)
END (* IF y-LONGREAL... *)
ELSE
IF (y-LONGREAL(TRUNC(y)) <> 0.0) THEN
RETURN 1.0E-308
ELSE
n:=1.0;
FOR i:=1 TO ABS(TRUNC(y)) DO
n:=n*x
END; (* FOR *)
IF y > 0.0 THEN
RETURN n
ELSE
RETURN 1.0/n
END
END
END
END power;
PROCEDURE fact ( x : LONGREAL ) : LONGREAL; (* Fakultät *)
VAR
i : INTEGER;
fac : LONGREAL;
BEGIN
fac:=1.0;
IF (x = 1.0) OR (x = 0.0) THEN
RETURN 1.0
ELSIF x < 0.0 THEN
RETURN 1.0E-308
ELSE
FOR i:=2 TO TRUNC(x) DO
fac:=fac+fac*( LONGREAL(i)-1.0 )
END; (* FOR *)
RETURN fac
END
END fact;
PROCEDURE sgn ( x : LONGREAL ) : LONGREAL;
(* Vorzeichen -1.0, 0.0 oder +1.0 *)
BEGIN
IF x = 0.0 THEN
RETURN 0.0
ELSE
RETURN x/ABS(x)
END (* IF *)
END sgn;
END LongMathLibExt.